<!doctype html>

<html>
<head>
  <link rel="shortcut icon" href="static/images/favicon.ico" type="image/x-icon">
  <title>offlinestatuscomponent.js (Closure Library API Documentation - JavaScript)</title>
  <link rel="stylesheet" href="static/css/base.css">
  <link rel="stylesheet" href="static/css/doc.css">
  <link rel="stylesheet" href="static/css/sidetree.css">
  <link rel="stylesheet" href="static/css/prettify.css">

  <script>
     var _staticFilePath = "static/";
     var _typeTreeName = "goog";
     var _fileTreeName = "Source";
  </script>

  <script src="static/js/doc.js">
  </script>


  <meta charset="utf8">
</head>

<body onload="grokdoc.onLoad();">

<div id="header">
  <div class="g-section g-tpl-50-50 g-split">
    <div class="g-unit g-first">
      <a id="logo" href="index.html">Closure Library API Documentation</a>
    </div>

    <div class="g-unit">
      <div class="g-c">
        <strong>Go to class or file:</strong>
        <input type="text" id="ac">
      </div>
    </div>
  </div>
</div>

<div class="clear"></div>

<h2><a href="closure_goog_ui_offlinestatuscomponent.js.html">offlinestatuscomponent.js</a></h2>

<pre class="prettyprint lang-js">
<a name="line1"></a>// Copyright 2007 The Closure Library Authors. All Rights Reserved.
<a name="line2"></a>//
<a name="line3"></a>// Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
<a name="line4"></a>// you may not use this file except in compliance with the License.
<a name="line5"></a>// You may obtain a copy of the License at
<a name="line6"></a>//
<a name="line7"></a>//      http://www.apache.org/licenses/LICENSE-2.0
<a name="line8"></a>//
<a name="line9"></a>// Unless required by applicable law or agreed to in writing, software
<a name="line10"></a>// distributed under the License is distributed on an &quot;AS-IS&quot; BASIS,
<a name="line11"></a>// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
<a name="line12"></a>// See the License for the specific language governing permissions and
<a name="line13"></a>// limitations under the License.
<a name="line14"></a>
<a name="line15"></a>/**
<a name="line16"></a> * @fileoverview A component that displays the offline status of an app.
<a name="line17"></a> * Currently, it is used to show an icon with a tootip for the status.
<a name="line18"></a> *
<a name="line19"></a> * @see ../demos/offline.html
<a name="line20"></a> */
<a name="line21"></a>
<a name="line22"></a>goog.provide(&#39;goog.ui.OfflineStatusComponent&#39;);
<a name="line23"></a>goog.provide(&#39;goog.ui.OfflineStatusComponent.StatusClassNames&#39;);
<a name="line24"></a>
<a name="line25"></a>goog.require(&#39;goog.dom.classes&#39;);
<a name="line26"></a>goog.require(&#39;goog.events.EventType&#39;);
<a name="line27"></a>goog.require(&#39;goog.gears.StatusType&#39;);
<a name="line28"></a>goog.require(&#39;goog.positioning&#39;);
<a name="line29"></a>goog.require(&#39;goog.positioning.AnchoredPosition&#39;);
<a name="line30"></a>goog.require(&#39;goog.positioning.Corner&#39;);
<a name="line31"></a>goog.require(&#39;goog.positioning.Overflow&#39;);
<a name="line32"></a>goog.require(&#39;goog.ui.Component&#39;);
<a name="line33"></a>goog.require(&#39;goog.ui.OfflineStatusCard.EventType&#39;);
<a name="line34"></a>goog.require(&#39;goog.ui.Popup&#39;);
<a name="line35"></a>
<a name="line36"></a>
<a name="line37"></a>
<a name="line38"></a>/**
<a name="line39"></a> * An offline status component.
<a name="line40"></a> * @param {goog.dom.DomHelper=} opt_domHelper Optional DOM helper.
<a name="line41"></a> * @constructor
<a name="line42"></a> * @extends {goog.ui.Component}
<a name="line43"></a> */
<a name="line44"></a>goog.ui.OfflineStatusComponent = function(opt_domHelper) {
<a name="line45"></a>  goog.ui.Component.call(this, opt_domHelper);
<a name="line46"></a>};
<a name="line47"></a>goog.inherits(goog.ui.OfflineStatusComponent, goog.ui.Component);
<a name="line48"></a>
<a name="line49"></a>
<a name="line50"></a>/**
<a name="line51"></a> * The className&#39;s to use for the element of the component for each status type.
<a name="line52"></a> * @enum {string}
<a name="line53"></a> */
<a name="line54"></a>goog.ui.OfflineStatusComponent.StatusClassNames = {
<a name="line55"></a>  NOT_INSTALLED: goog.getCssName(&#39;goog-offlinestatus-notinstalled&#39;),
<a name="line56"></a>  INSTALLED: goog.getCssName(&#39;goog-offlinestatus-installed&#39;),
<a name="line57"></a>  PAUSED: goog.getCssName(&#39;goog-offlinestatus-paused&#39;),
<a name="line58"></a>  OFFLINE: goog.getCssName(&#39;goog-offlinestatus-offline&#39;),
<a name="line59"></a>  ONLINE: goog.getCssName(&#39;goog-offlinestatus-online&#39;),
<a name="line60"></a>  SYNCING: goog.getCssName(&#39;goog-offlinestatus-syncing&#39;),
<a name="line61"></a>  ERROR: goog.getCssName(&#39;goog-offlinestatus-error&#39;)
<a name="line62"></a>};
<a name="line63"></a>
<a name="line64"></a>
<a name="line65"></a>/**
<a name="line66"></a> * Whether the component is dirty and requires an upate to its display.
<a name="line67"></a> * @type {boolean}
<a name="line68"></a> * @private
<a name="line69"></a> */
<a name="line70"></a>goog.ui.OfflineStatusComponent.prototype.dirty_ = false;
<a name="line71"></a>
<a name="line72"></a>
<a name="line73"></a>/**
<a name="line74"></a> * The status of the component.
<a name="line75"></a> * @type {goog.gears.StatusType}
<a name="line76"></a> * @private
<a name="line77"></a> */
<a name="line78"></a>goog.ui.OfflineStatusComponent.prototype.status_ =
<a name="line79"></a>    goog.gears.StatusType.NOT_INSTALLED;
<a name="line80"></a>
<a name="line81"></a>
<a name="line82"></a>/**
<a name="line83"></a> * The status of the component that is displayed.
<a name="line84"></a> * @type {goog.gears.StatusType?}
<a name="line85"></a> * @private
<a name="line86"></a> */
<a name="line87"></a>goog.ui.OfflineStatusComponent.prototype.displayedStatus_ = null;
<a name="line88"></a>
<a name="line89"></a>
<a name="line90"></a>/**
<a name="line91"></a> * The dialog that manages the install flow.
<a name="line92"></a> * @type {goog.ui.OfflineInstallDialog?}
<a name="line93"></a> * @private
<a name="line94"></a> */
<a name="line95"></a>goog.ui.OfflineStatusComponent.prototype.dialog_ = null;
<a name="line96"></a>
<a name="line97"></a>
<a name="line98"></a>/**
<a name="line99"></a> * The card for displaying the detailed status.
<a name="line100"></a> * @type {goog.ui.OfflineStatusCard?}
<a name="line101"></a> * @private
<a name="line102"></a> */
<a name="line103"></a>goog.ui.OfflineStatusComponent.prototype.card_ = null;
<a name="line104"></a>
<a name="line105"></a>
<a name="line106"></a>/**
<a name="line107"></a> * The popup for the OfflineStatusCard.
<a name="line108"></a> * @type {goog.ui.Popup?}
<a name="line109"></a> * @private
<a name="line110"></a> */
<a name="line111"></a>goog.ui.OfflineStatusComponent.prototype.popup_ = null;
<a name="line112"></a>
<a name="line113"></a>
<a name="line114"></a>/**
<a name="line115"></a> * CSS class name for the element.
<a name="line116"></a> * @type {string}
<a name="line117"></a> * @private
<a name="line118"></a> */
<a name="line119"></a>goog.ui.OfflineStatusComponent.prototype.className_ =
<a name="line120"></a>    goog.getCssName(&#39;goog-offlinestatus&#39;);
<a name="line121"></a>
<a name="line122"></a>
<a name="line123"></a>/**
<a name="line124"></a> * @desc New feature text for the offline acces feature.
<a name="line125"></a> * @type {string}
<a name="line126"></a> * @private
<a name="line127"></a> */
<a name="line128"></a>goog.ui.OfflineStatusComponent.prototype.MSG_OFFLINE_NEW_FEATURE_ =
<a name="line129"></a>    goog.getMsg(&#39;New! Offline Access&#39;);
<a name="line130"></a>
<a name="line131"></a>
<a name="line132"></a>/**
<a name="line133"></a> * @desc Connectivity status of the app indicating the app is paused (user
<a name="line134"></a> * initiated offline).
<a name="line135"></a> * @type {string}
<a name="line136"></a> * @private
<a name="line137"></a> */
<a name="line138"></a>goog.ui.OfflineStatusComponent.prototype.MSG_OFFLINE_STATUS_PAUSED_TITLE_ =
<a name="line139"></a>    goog.getMsg(&#39;Paused (offline). Click to connect.&#39;);
<a name="line140"></a>
<a name="line141"></a>
<a name="line142"></a>/**
<a name="line143"></a> * @desc Connectivity status of the app indicating the app is offline.
<a name="line144"></a> * @type {string}
<a name="line145"></a> * @private
<a name="line146"></a> */
<a name="line147"></a>goog.ui.OfflineStatusComponent.prototype.MSG_OFFLINE_STATUS_OFFLINE_TITLE_ =
<a name="line148"></a>    goog.getMsg(&#39;Offline. No connection available.&#39;);
<a name="line149"></a>
<a name="line150"></a>
<a name="line151"></a>/**
<a name="line152"></a> * @desc Connectivity status of the app indicating the app is online.
<a name="line153"></a> * @type {string}
<a name="line154"></a> * @private
<a name="line155"></a> */
<a name="line156"></a>goog.ui.OfflineStatusComponent.prototype.MSG_OFFLINE_STATUS_ONLINE_TITLE_ =
<a name="line157"></a>    goog.getMsg(&#39;Online. Click for details.&#39;);
<a name="line158"></a>
<a name="line159"></a>
<a name="line160"></a>/**
<a name="line161"></a> * @desc Connectivity status of the app indicating the app is synchronizing with
<a name="line162"></a> * the server.
<a name="line163"></a> * @type {string}
<a name="line164"></a> * @private
<a name="line165"></a> */
<a name="line166"></a>goog.ui.OfflineStatusComponent.prototype.MSG_OFFLINE_STATUS_SYNCING_TITLE_ =
<a name="line167"></a>    goog.getMsg(&#39;Synchronizing. Click for details.&#39;);
<a name="line168"></a>
<a name="line169"></a>
<a name="line170"></a>/**
<a name="line171"></a> * @desc Connectivity status of the app indicating errors have been found.
<a name="line172"></a> * @type {string}
<a name="line173"></a> * @private
<a name="line174"></a> */
<a name="line175"></a>goog.ui.OfflineStatusComponent.prototype.MSG_OFFLINE_STATUS_ERROR_TITLE_ =
<a name="line176"></a>    goog.getMsg(&#39;Errors found. Click for details.&#39;);
<a name="line177"></a>
<a name="line178"></a>
<a name="line179"></a>/**
<a name="line180"></a> * Gets the status of the offline component of the app.
<a name="line181"></a> * @return {goog.gears.StatusType} The offline status.
<a name="line182"></a> */
<a name="line183"></a>goog.ui.OfflineStatusComponent.prototype.getStatus = function() {
<a name="line184"></a>  return this.status_;
<a name="line185"></a>};
<a name="line186"></a>
<a name="line187"></a>
<a name="line188"></a>/**
<a name="line189"></a> * Sets the status of the offline component of the app.
<a name="line190"></a> * @param {goog.gears.StatusType} status The offline
<a name="line191"></a> *     status.
<a name="line192"></a> */
<a name="line193"></a>goog.ui.OfflineStatusComponent.prototype.setStatus = function(status) {
<a name="line194"></a>  if (this.isStatusDifferent(status)) {
<a name="line195"></a>    this.dirty_ = true;
<a name="line196"></a>  }
<a name="line197"></a>
<a name="line198"></a>  this.status_ = status;
<a name="line199"></a>  if (this.isInDocument()) {
<a name="line200"></a>    this.update();
<a name="line201"></a>  }
<a name="line202"></a>
<a name="line203"></a>  // Set the status of the card, if necessary.
<a name="line204"></a>  if (this.card_) {
<a name="line205"></a>    this.card_.setStatus(status);
<a name="line206"></a>  }
<a name="line207"></a>};
<a name="line208"></a>
<a name="line209"></a>
<a name="line210"></a>/**
<a name="line211"></a> * Returns whether the given status is different from the currently
<a name="line212"></a> * recorded status.
<a name="line213"></a> * @param {goog.gears.StatusType} status The offline status.
<a name="line214"></a> * @return {boolean} Whether the status is different.
<a name="line215"></a> */
<a name="line216"></a>goog.ui.OfflineStatusComponent.prototype.isStatusDifferent = function(status) {
<a name="line217"></a>  return this.status_ != status;
<a name="line218"></a>};
<a name="line219"></a>
<a name="line220"></a>
<a name="line221"></a>/**
<a name="line222"></a> * Sets the install dialog.
<a name="line223"></a> * @param {goog.ui.OfflineInstallDialog} dialog The dialog.
<a name="line224"></a> */
<a name="line225"></a>goog.ui.OfflineStatusComponent.prototype.setInstallDialog = function(dialog) {
<a name="line226"></a>  // If there is a current dialog, remove it.
<a name="line227"></a>  if (this.dialog_ &amp;&amp; this.indexOfChild(this.dialog_) &gt;= 0) {
<a name="line228"></a>    this.removeChild(this.dialog_);
<a name="line229"></a>  }
<a name="line230"></a>  this.dialog_ = dialog;
<a name="line231"></a>};
<a name="line232"></a>
<a name="line233"></a>
<a name="line234"></a>/**
<a name="line235"></a> * Gets the install dialog.
<a name="line236"></a> * @return {goog.ui.OfflineInstallDialog} dialog The dialog.
<a name="line237"></a> */
<a name="line238"></a>goog.ui.OfflineStatusComponent.prototype.getInstallDialog = function() {
<a name="line239"></a>  return this.dialog_;
<a name="line240"></a>};
<a name="line241"></a>
<a name="line242"></a>
<a name="line243"></a>/**
<a name="line244"></a> * Sets the status card.
<a name="line245"></a> * @param {goog.ui.OfflineStatusCard} card The card.
<a name="line246"></a> */
<a name="line247"></a>goog.ui.OfflineStatusComponent.prototype.setStatusCard = function(card) {
<a name="line248"></a>  // If there is a current card, remove it.
<a name="line249"></a>  if (this.card_) {
<a name="line250"></a>    this.getHandler().unlisten(this.card_,
<a name="line251"></a>        goog.ui.OfflineStatusCard.EventType.DISMISS,
<a name="line252"></a>        this.performStatusAction, false, this);
<a name="line253"></a>    this.popup_.dispose();
<a name="line254"></a>    if (this.indexOfChild(this.card_) &gt;= 0) {
<a name="line255"></a>      this.removeChild(this.card_);
<a name="line256"></a>    }
<a name="line257"></a>    this.popup_ = null;
<a name="line258"></a>    this.card_ = null;
<a name="line259"></a>  }
<a name="line260"></a>  this.card_ = card;
<a name="line261"></a>  this.getHandler().listen(this.card_,
<a name="line262"></a>      goog.ui.OfflineStatusCard.EventType.DISMISS,
<a name="line263"></a>      this.performStatusAction, false, this);
<a name="line264"></a>  card.setStatus(this.status_);
<a name="line265"></a>};
<a name="line266"></a>
<a name="line267"></a>
<a name="line268"></a>/**
<a name="line269"></a> * Gets the status card.
<a name="line270"></a> * @return {goog.ui.OfflineStatusCard} The card.
<a name="line271"></a> */
<a name="line272"></a>goog.ui.OfflineStatusComponent.prototype.getStatusCard = function() {
<a name="line273"></a>  return this.card_;
<a name="line274"></a>};
<a name="line275"></a>
<a name="line276"></a>
<a name="line277"></a>/**
<a name="line278"></a> * Creates the initial DOM representation for the component.
<a name="line279"></a> * @override
<a name="line280"></a> */
<a name="line281"></a>goog.ui.OfflineStatusComponent.prototype.createDom = function() {
<a name="line282"></a>  var anchorProps = {
<a name="line283"></a>    &#39;class&#39;: this.className_,
<a name="line284"></a>    &#39;href&#39;: &#39;#&#39;
<a name="line285"></a>  };
<a name="line286"></a>  this.setElementInternal(
<a name="line287"></a>      this.getDomHelper().createDom(&#39;a&#39;, anchorProps));
<a name="line288"></a>  this.update();
<a name="line289"></a>};
<a name="line290"></a>
<a name="line291"></a>
<a name="line292"></a>/** @override */
<a name="line293"></a>goog.ui.OfflineStatusComponent.prototype.enterDocument = function() {
<a name="line294"></a>  goog.ui.OfflineStatusComponent.superClass_.enterDocument.call(this);
<a name="line295"></a>
<a name="line296"></a>  this.getHandler().listen(
<a name="line297"></a>      this.getElement(), goog.events.EventType.CLICK, this.handleClick_);
<a name="line298"></a>
<a name="line299"></a>  if (this.dirty_) {
<a name="line300"></a>    this.update();
<a name="line301"></a>  }
<a name="line302"></a>};
<a name="line303"></a>
<a name="line304"></a>
<a name="line305"></a>/**
<a name="line306"></a> * Updates the display of the component.
<a name="line307"></a> */
<a name="line308"></a>goog.ui.OfflineStatusComponent.prototype.update = function() {
<a name="line309"></a>  if (this.getElement()) {
<a name="line310"></a>    var status = this.getStatus();
<a name="line311"></a>    var messageInfo = this.getMessageInfo(status);
<a name="line312"></a>
<a name="line313"></a>    // Set the title.
<a name="line314"></a>    var element = this.getElement();
<a name="line315"></a>    element.title = messageInfo.title;
<a name="line316"></a>
<a name="line317"></a>    // Set the appropriate class.
<a name="line318"></a>    var previousStatus = this.displayStatus_;
<a name="line319"></a>    var previousStatusClassName = this.getStatusClassName_(previousStatus);
<a name="line320"></a>    var currentStatusClassName = this.getStatusClassName_(status);
<a name="line321"></a>    if (previousStatus &amp;&amp;
<a name="line322"></a>        goog.dom.classes.has(element, previousStatusClassName)) {
<a name="line323"></a>      goog.dom.classes.swap(
<a name="line324"></a>          element, previousStatusClassName, currentStatusClassName);
<a name="line325"></a>    } else {
<a name="line326"></a>      goog.dom.classes.add(element, currentStatusClassName);
<a name="line327"></a>    }
<a name="line328"></a>
<a name="line329"></a>    // Set the current display status
<a name="line330"></a>    this.displayStatus_ = status;
<a name="line331"></a>
<a name="line332"></a>    // Set the text.
<a name="line333"></a>    if (messageInfo.textIsHtml) {
<a name="line334"></a>      element.innerHTML = messageInfo.text;
<a name="line335"></a>    } else {
<a name="line336"></a>      this.getDomHelper().setTextContent(element, messageInfo.text);
<a name="line337"></a>    }
<a name="line338"></a>
<a name="line339"></a>    // Clear the dirty state.
<a name="line340"></a>    this.dirty_ = false;
<a name="line341"></a>  }
<a name="line342"></a>};
<a name="line343"></a>
<a name="line344"></a>
<a name="line345"></a>/**
<a name="line346"></a> * Gets the messaging info for the given status.
<a name="line347"></a> * @param {goog.gears.StatusType} status Status to get the message info for.
<a name="line348"></a> * @return {Object} Object that has three properties - text (string),
<a name="line349"></a> *     textIsHtml (boolean), and title (string).
<a name="line350"></a> */
<a name="line351"></a>goog.ui.OfflineStatusComponent.prototype.getMessageInfo = function(status) {
<a name="line352"></a>  var title = &#39;&#39;;
<a name="line353"></a>  var text = &#39;&amp;nbsp;&amp;nbsp;&amp;nbsp;&#39;;
<a name="line354"></a>  var textIsHtml = true;
<a name="line355"></a>
<a name="line356"></a>  switch (status) {
<a name="line357"></a>    case goog.gears.StatusType.NOT_INSTALLED:
<a name="line358"></a>    case goog.gears.StatusType.INSTALLED:
<a name="line359"></a>      text = this.MSG_OFFLINE_NEW_FEATURE_;
<a name="line360"></a>      textIsHtml = false;
<a name="line361"></a>      break;
<a name="line362"></a>    case goog.gears.StatusType.PAUSED:
<a name="line363"></a>      title = this.MSG_OFFLINE_STATUS_PAUSED_TITLE_;
<a name="line364"></a>      break;
<a name="line365"></a>    case goog.gears.StatusType.OFFLINE:
<a name="line366"></a>      title = this.MSG_OFFLINE_STATUS_OFFLINE_TITLE_;
<a name="line367"></a>      break;
<a name="line368"></a>    case goog.gears.StatusType.ONLINE:
<a name="line369"></a>      title = this.MSG_OFFLINE_STATUS_ONLINE_TITLE_;
<a name="line370"></a>      break;
<a name="line371"></a>    case goog.gears.StatusType.SYNCING:
<a name="line372"></a>      title = this.MSG_OFFLINE_STATUS_SYNCING_TITLE_;
<a name="line373"></a>      break;
<a name="line374"></a>    case goog.gears.StatusType.ERROR:
<a name="line375"></a>      title = this.MSG_OFFLINE_STATUS_ERROR_TITLE_;
<a name="line376"></a>      break;
<a name="line377"></a>    default:
<a name="line378"></a>      break;
<a name="line379"></a>  }
<a name="line380"></a>
<a name="line381"></a>  return {text: text, textIsHtml: textIsHtml, title: title};
<a name="line382"></a>};
<a name="line383"></a>
<a name="line384"></a>
<a name="line385"></a>/**
<a name="line386"></a> * Gets the CSS className for the given status.
<a name="line387"></a> * @param {goog.gears.StatusType} status Status to get the className for.
<a name="line388"></a> * @return {string} The className.
<a name="line389"></a> * @private
<a name="line390"></a> */
<a name="line391"></a>goog.ui.OfflineStatusComponent.prototype.getStatusClassName_ = function(
<a name="line392"></a>    status) {
<a name="line393"></a>  var className = &#39;&#39;;
<a name="line394"></a>  switch (status) {
<a name="line395"></a>    case goog.gears.StatusType.NOT_INSTALLED:
<a name="line396"></a>      className =
<a name="line397"></a>          goog.ui.OfflineStatusComponent.StatusClassNames.NOT_INSTALLED;
<a name="line398"></a>      break;
<a name="line399"></a>    case goog.gears.StatusType.INSTALLED:
<a name="line400"></a>      className = goog.ui.OfflineStatusComponent.StatusClassNames.INSTALLED;
<a name="line401"></a>      break;
<a name="line402"></a>    case goog.gears.StatusType.PAUSED:
<a name="line403"></a>      className = goog.ui.OfflineStatusComponent.StatusClassNames.PAUSED;
<a name="line404"></a>      break;
<a name="line405"></a>    case goog.gears.StatusType.OFFLINE:
<a name="line406"></a>      className = goog.ui.OfflineStatusComponent.StatusClassNames.OFFLINE;
<a name="line407"></a>      break;
<a name="line408"></a>    case goog.gears.StatusType.ONLINE:
<a name="line409"></a>      className = goog.ui.OfflineStatusComponent.StatusClassNames.ONLINE;
<a name="line410"></a>      break;
<a name="line411"></a>    case goog.gears.StatusType.SYNCING:
<a name="line412"></a>    case goog.gears.StatusType.CAPTURING:
<a name="line413"></a>      className = goog.ui.OfflineStatusComponent.StatusClassNames.SYNCING;
<a name="line414"></a>      break;
<a name="line415"></a>    case goog.gears.StatusType.ERROR:
<a name="line416"></a>      className = goog.ui.OfflineStatusComponent.StatusClassNames.ERROR;
<a name="line417"></a>      break;
<a name="line418"></a>    default:
<a name="line419"></a>      break;
<a name="line420"></a>  }
<a name="line421"></a>  return className;
<a name="line422"></a>};
<a name="line423"></a>
<a name="line424"></a>
<a name="line425"></a>/**
<a name="line426"></a> * Handles a click on the component. Opens the applicable install dialog or
<a name="line427"></a> * status card.
<a name="line428"></a> * @param {goog.events.BrowserEvent} e The event.
<a name="line429"></a> * @private
<a name="line430"></a> * @return {boolean|undefined} Always false to prevent the anchor navigation.
<a name="line431"></a> */
<a name="line432"></a>goog.ui.OfflineStatusComponent.prototype.handleClick_ = function(e) {
<a name="line433"></a>  this.performAction();
<a name="line434"></a>  return false;
<a name="line435"></a>};
<a name="line436"></a>
<a name="line437"></a>
<a name="line438"></a>/**
<a name="line439"></a> * Performs the action as if the component was clicked.
<a name="line440"></a> */
<a name="line441"></a>goog.ui.OfflineStatusComponent.prototype.performAction = function() {
<a name="line442"></a>  var status = this.getStatus();
<a name="line443"></a>
<a name="line444"></a>  if (status == goog.gears.StatusType.NOT_INSTALLED ||
<a name="line445"></a>      status == goog.gears.StatusType.INSTALLED) {
<a name="line446"></a>    this.performEnableAction();
<a name="line447"></a>  } else {
<a name="line448"></a>    this.performStatusAction();
<a name="line449"></a>  }
<a name="line450"></a>};
<a name="line451"></a>
<a name="line452"></a>
<a name="line453"></a>/**
<a name="line454"></a> * Performs the action to start the flow of enabling the offline feature of
<a name="line455"></a> * the application.
<a name="line456"></a> */
<a name="line457"></a>goog.ui.OfflineStatusComponent.prototype.performEnableAction = function() {
<a name="line458"></a>  // If Gears is not installed or if it is installed but not enabled, then
<a name="line459"></a>  // show the install dialog.
<a name="line460"></a>  var dialog = this.dialog_;
<a name="line461"></a>  if (dialog) {
<a name="line462"></a>    if (!dialog.isInDocument()) {
<a name="line463"></a>      this.addChild(dialog);
<a name="line464"></a>      dialog.render(this.getDomHelper().getDocument().body);
<a name="line465"></a>    }
<a name="line466"></a>    dialog.setVisible(true);
<a name="line467"></a>  }
<a name="line468"></a>};
<a name="line469"></a>
<a name="line470"></a>
<a name="line471"></a>/**
<a name="line472"></a> * Performs the action to show the offline status.
<a name="line473"></a> * @param {goog.events.Event=} opt_evt Event.
<a name="line474"></a> * @param {Element=} opt_element Optional element to anchor the card against.
<a name="line475"></a> */
<a name="line476"></a>goog.ui.OfflineStatusComponent.prototype.performStatusAction = function(opt_evt,
<a name="line477"></a>    opt_element) {
<a name="line478"></a>  // Shows the offline status card.
<a name="line479"></a>  var card = this.card_;
<a name="line480"></a>  if (card) {
<a name="line481"></a>    if (!this.popup_) {
<a name="line482"></a>      if (!card.getElement()) {
<a name="line483"></a>        card.createDom();
<a name="line484"></a>      }
<a name="line485"></a>      this.insertCardElement(card);
<a name="line486"></a>      this.addChild(card);
<a name="line487"></a>      var popup = this.getPopupInternal();
<a name="line488"></a>      var anchorEl = opt_element || this.getElement();
<a name="line489"></a>      var pos = new goog.positioning.AnchoredPosition(
<a name="line490"></a>          anchorEl, goog.positioning.Corner.BOTTOM_START,
<a name="line491"></a>          goog.positioning.Overflow.ADJUST_X);
<a name="line492"></a>      popup.setPosition(pos);
<a name="line493"></a>      popup.setElement(card.getElement());
<a name="line494"></a>    }
<a name="line495"></a>    this.popup_.setVisible(!this.popup_.isOrWasRecentlyVisible());
<a name="line496"></a>  }
<a name="line497"></a>};
<a name="line498"></a>
<a name="line499"></a>
<a name="line500"></a>/**
<a name="line501"></a> * Inserts the card into the document body.
<a name="line502"></a> * @param {goog.ui.OfflineStatusCard} card The offline status card.
<a name="line503"></a> * @protected
<a name="line504"></a> */
<a name="line505"></a>goog.ui.OfflineStatusComponent.prototype.insertCardElement = function(card) {
<a name="line506"></a>  this.getDomHelper().getDocument().body.appendChild(card.getElement());
<a name="line507"></a>};
<a name="line508"></a>
<a name="line509"></a>
<a name="line510"></a>/**
<a name="line511"></a> * @return {goog.ui.Popup} A popup object, if none exists a new one is created.
<a name="line512"></a> * @protected
<a name="line513"></a> */
<a name="line514"></a>goog.ui.OfflineStatusComponent.prototype.getPopupInternal = function() {
<a name="line515"></a>  if (!this.popup_) {
<a name="line516"></a>    this.popup_ = new goog.ui.Popup();
<a name="line517"></a>    this.popup_.setMargin(3, 0, 0, 0);
<a name="line518"></a>  }
<a name="line519"></a>  return this.popup_;
<a name="line520"></a>};
<a name="line521"></a>
<a name="line522"></a>
<a name="line523"></a>/** @override */
<a name="line524"></a>goog.ui.OfflineStatusComponent.prototype.disposeInternal = function() {
<a name="line525"></a>  goog.ui.OfflineStatusComponent.superClass_.disposeInternal.call(this);
<a name="line526"></a>
<a name="line527"></a>  if (this.dialog_) {
<a name="line528"></a>    this.dialog_.dispose();
<a name="line529"></a>    this.dialog_ = null;
<a name="line530"></a>  }
<a name="line531"></a>
<a name="line532"></a>  if (this.card_) {
<a name="line533"></a>    this.card_.dispose();
<a name="line534"></a>    this.card_ = null;
<a name="line535"></a>  }
<a name="line536"></a>
<a name="line537"></a>  if (this.popup_) {
<a name="line538"></a>    this.popup_.dispose();
<a name="line539"></a>    this.popup_ = null;
<a name="line540"></a>  }
<a name="line541"></a>};
</pre>


</body>
</html>
